package com.guashu.springbootdistributedid.demo;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Base64;

public class BatchBase64ToImageConverter {

    public static void main(String[] args) {
        String inputFilePath = "E:\\国银租赁\\观微文档\\out.txt";
        String outputFolderPath = "E:\\国银租赁\\观微文档\\restored_images";

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFilePath), "UTF-8"));

            String line;
            while ((line = reader.readLine()) != null) {
                if (line.startsWith("File: ")) {
                    String fileName = line.substring("File: ".length());
                    String base64Data = reader.readLine().trim();
                    byte[] imageBytes = Base64.getDecoder().decode(base64Data);

                    Path outputPath = Paths.get(outputFolderPath, fileName);
                    Files.createDirectories(outputPath.getParent());
                    Files.write(outputPath, imageBytes);

                    System.out.println("Image \"" + fileName + "\" restored.");
                }
            }
            reader.close();
            System.out.println("All images have been restored.");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

